package com.as.service.plugin;

import javax.servlet.ServletException;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

import com.as.service.application.ApplicationContainer;
import com.as.service.factory.IServiceFactory;
import com.as.service.factory.ServiceFactoryImp;
import com.as.service.util.IConstants;



public class ServicePlugin implements PlugIn {
	
	private IServiceFactory servicefactory = null;
	private ApplicationContainer applicationContainer = null;
	
	public void destroy() {
		servicefactory = null;
		applicationContainer = null;
	}

	public void init(ActionServlet servlet, ModuleConfig module) throws ServletException {
		
		try {
			servicefactory = ServiceFactoryImp.getInstance();
			applicationContainer = new ApplicationContainer();
		} catch (Exception e) {
			throw new ServletException(e.getMessage());
		}
		servlet.getServletContext().setAttribute(IConstants.APPLICATION_CONTAINER_KEY, applicationContainer);
		servlet.getServletContext().setAttribute(IConstants.SERVICE_FACTORY_INTERFACE_KEY, servicefactory);
	}
}
